from pathlib import Path


def getAbsoluteFolderPath():
    """
    return: 文件夹的绝对路径
    """
    return Path.cwd()


def getUserFolderPath():
    """
    return: 当前用户文件夹的路径
    """
    return Path.home()


def getPathParts(path):
    """
    param path:需要拆分的路径
    return:根据目录分隔符将路径分解返回一个元组
    """
    p = Path(path)
    return p.parts


def getExpectPathLength(path, length):
    """
    param path:目标路径
    return:根据length判断返回上级目录
    """
    p = Path(path)
    temp = p.parents
    if len(temp) >= length:
        return temp[length-1]
    elif length == 0:
        raise Exception("length shall not equal to 1")
    else:
        raise Exception("length out of range")


def checkObjectExists(path):
    """
    param path: 文件的绝对路径
    return: True/False
    """
    p = Path(path)
    return p.exists()


def checkPathIsAbsolute(path):
    """
    param path: 判断的路径
    return: True/False
    """
    p = Path(path)
    return p.is_absolute()

